home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / drivers / scsi / hosts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  6.2 KB  |  270 lines

  1. /*
  2.  *    hosts.c Copyright (C) 1992 Drew Eckhardt
  3.  *    mid to lowlevel SCSI driver interface by
  4.  *        Drew Eckhardt
  5.  *
  6.  *    <drew@colorado.edu>
  7.  */
  8.  
  9.  
  10. /*
  11.  *    This file contains the medium level SCSI
  12.  *    host interface initialization, as well as the scsi_hosts array of SCSI
  13.  *    hosts currently present in the system.
  14.  */
  15.  
  16. #include <linux/config.h>
  17. #include "../block/blk.h"
  18. #include <linux/kernel.h>
  19. #include <linux/string.h>
  20. #include "scsi.h"
  21.  
  22. #ifndef NULL
  23. #define NULL 0L
  24. #endif
  25.  
  26. #define HOSTS_C
  27.  
  28. #include "hosts.h"
  29.  
  30. #ifdef CONFIG_A3000_SCSI
  31. #include "a3000.h"
  32. #endif
  33.  
  34. #ifdef CONFIG_A2091_SCSI
  35. #include "a2091.h"
  36. #endif
  37.  
  38. #ifdef CONFIG_GVP11_SCSI
  39. #include "gvp11.h"
  40. #endif
  41.  
  42. #ifdef CONFIG_SCSI_DEBUG
  43. #include "scsi_debug.h"
  44. #endif
  45.  
  46. #ifdef CONFIG_SCSI_GENERIC_NCR5380
  47. #include "g_NCR5380.h"
  48. #endif
  49.  
  50. #if CONFIG_ATARI_SCSI
  51. #include "atari_scsi.h"
  52. #endif
  53.  
  54. /*
  55. static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/hosts.c,v 1.3 1993/09/24 12:21:00 drew Exp drew $";
  56. */
  57.  
  58. /*
  59.  *    The scsi host entries should be in the order you wish the
  60.  *    cards to be detected.  A driver may appear more than once IFF
  61.  *    it can deal with being detected (and therefore initialized)
  62.  *    with more than one simulatenous host number, can handle being
  63.  *    rentrant, etc.
  64.  *
  65.  *    They may appear in any order, as each SCSI host  is told which host number it is
  66.  *    during detection.
  67.  */
  68.  
  69. /* This is a placeholder for controllers that are not configured into
  70.    the system - we do this to ensure that the controller numbering is
  71.    always consistent, no matter how the kernel is configured. */
  72.  
  73. #define NO_CONTROLLER {NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
  74.         NULL, NULL, 0, 0, 0, 0, 0, 0}
  75.  
  76. /*
  77.  *    When figure is run, we don't want to link to any object code.  Since
  78.  *    the macro for each host will contain function pointers, we cannot
  79.  *    use it and instead must use a "blank" that does no such
  80.  *    idiocy.
  81.  */
  82.  
  83. Scsi_Host_Template scsi_hosts[] =
  84.     {
  85. #ifdef CONFIG_A3000_SCSI
  86.     A3000_SCSI,
  87. #endif
  88. #ifdef CONFIG_A2091_SCSI
  89.     A2091_SCSI,
  90. #endif
  91. #ifdef CONFIG_GVP11_SCSI
  92.     GVP11_SCSI,
  93. #endif
  94. #ifdef CONFIG_SCSI_DEBUG
  95.     SCSI_DEBUG,
  96. #endif
  97. #ifdef CONFIG_SCSI_GENERIC_NCR5380
  98.     GENERIC_NCR5380,
  99. #endif
  100. #if CONFIG_ATARI_SCSI
  101.     ATARI_SCSI,
  102. #endif
  103.     };
  104.  
  105. #define MAX_SCSI_HOSTS (sizeof(scsi_hosts) / sizeof(Scsi_Host_Template))
  106.  
  107. /*
  108.  *    Our semaphores and timeout counters, where size depends on MAX_SCSI_HOSTS here.
  109.  */
  110.  
  111. struct Scsi_Host *scsi_hostlist = NULL;
  112.  
  113. static int scsi_init_memory_start = 0;
  114.  
  115. int max_scsi_hosts = 0;
  116. static int next_host = 0;
  117.  
  118. void
  119. scsi_unregister(struct Scsi_Host * sh, int j){
  120.     struct Scsi_Host * shpnt;
  121.  
  122.     if(((unsigned int) sh) + sizeof(struct Scsi_Host) + j != scsi_init_memory_start)
  123.         panic("Unable to unregister scsi host");
  124.     if(scsi_hostlist == sh)
  125.         scsi_hostlist = NULL;
  126.     else {
  127.         shpnt = scsi_hostlist;
  128.         while(shpnt->next != sh) shpnt = shpnt->next;
  129.         shpnt->next = shpnt->next->next;
  130.  
  131.     };
  132.     next_host--;
  133.     scsi_init_memory_start = (unsigned int) sh;
  134. }
  135.  
  136. /* We call this when we come across a new host adapter. We only do this
  137.    once we are 100% sure that we want to use this host adapter -  it is a
  138.    pain to reverse this, so we try and avoid it */
  139.  
  140. struct Scsi_Host * scsi_register(int i, int j){
  141.     struct Scsi_Host * retval, *shpnt;
  142.     retval = (struct Scsi_Host*) scsi_init_memory_start;
  143.     scsi_init_memory_start += sizeof(struct Scsi_Host) + j;
  144.     retval->host_busy = 0;
  145.     retval->host_no = next_host++;
  146.     retval->host_queue = NULL;    
  147.     retval->host_wait = NULL;    
  148.     retval->last_reset = 0;    
  149.     retval->hostt = &scsi_hosts[i];    
  150.     retval->next = NULL;
  151. #ifdef DEBUG
  152.     printk("Register %p %p: %d %d\n", retval, retval->hostt, i, j);
  153. #endif
  154.  
  155.     /* The next three are the default values which can be overridden
  156.        if need be */
  157.     retval->this_id = scsi_hosts[i].this_id;
  158.     retval->sg_tablesize = scsi_hosts[i].sg_tablesize;
  159.     retval->unchecked_isa_dma = scsi_hosts[i].unchecked_isa_dma;
  160.  
  161.     if(!scsi_hostlist)
  162.         scsi_hostlist = retval;
  163.     else
  164.     {
  165.         shpnt = scsi_hostlist;
  166.         while(shpnt->next) shpnt = shpnt->next;
  167.         shpnt->next = retval;
  168.     }
  169.  
  170.     return retval;
  171. }
  172.  
  173. unsigned int
  174. scsi_init(unsigned long memory_start,unsigned long memory_end)
  175. {
  176.     static int called = 0;
  177.     int i, j, count, pcount;
  178.  
  179.     count = 0;
  180.  
  181.     if(called) return memory_start;
  182.  
  183.     scsi_init_memory_start = memory_start;
  184.     called = 1;    
  185.     for (i = 0; i < MAX_SCSI_HOSTS; ++i)
  186.     {
  187.         /*
  188.          * Initialize our semaphores.  -1 is interpreted to mean 
  189.          * "inactive" - where as 0 will indicate a time out condition.
  190.          */ 
  191.         
  192.         pcount = next_host;
  193.         if ((scsi_hosts[i].detect) && 
  194.             (scsi_hosts[i].present = 
  195.              scsi_hosts[i].detect(i)))
  196.         {        
  197.             /* The only time this should come up is when people use
  198.                some kind of patched driver of some kind or another. */
  199.             if(pcount == next_host) {
  200.                 if(scsi_hosts[i].present > 1)
  201.                     panic("Failure to register low-level scsi driver");
  202.                 /* The low-level driver failed to register a driver.  We
  203.                    can do this now. */
  204.                 scsi_register(i,0);
  205.             };
  206.             for(j = 0; j < scsi_hosts[i].present; j++)
  207.                 printk ("scsi%d : %s\n",
  208.                     count++, scsi_hosts[i].name);
  209.         }
  210.     }
  211.     printk ("scsi : %d hosts.\n", count);
  212.     
  213.     max_scsi_hosts = count;
  214.     return scsi_init_memory_start;
  215. }
  216.  
  217. #ifndef CONFIG_BLK_DEV_SD
  218. unsigned long sd_init(unsigned long memory_start, unsigned long memory_end){
  219.   return memory_start;
  220. };
  221. unsigned long sd_init1(unsigned long memory_start, unsigned long memory_end){
  222.   return memory_start;
  223. };
  224. void sd_attach(Scsi_Device * SDp){
  225. };
  226. int NR_SD=-1;
  227. int MAX_SD=0;
  228. #endif
  229.  
  230.  
  231. #ifndef CONFIG_BLK_DEV_SR
  232. unsigned long sr_init(unsigned long memory_start, unsigned long memory_end){
  233.   return memory_start;
  234. };
  235. unsigned long sr_init1(unsigned long memory_start, unsigned long memory_end){
  236.   return memory_start;
  237. };
  238. void sr_attach(Scsi_Device * SDp){
  239. };
  240. int NR_SR=-1;
  241. int MAX_SR=0;
  242. #endif
  243.  
  244.  
  245. #ifndef CONFIG_CHR_DEV_ST
  246. unsigned long st_init(unsigned long memory_start, unsigned long memory_end){
  247.   return memory_start;
  248. };
  249. unsigned long st_init1(unsigned long memory_start, unsigned long memory_end){
  250.   return memory_start;
  251. };
  252. void st_attach(Scsi_Device * SDp){
  253. };
  254. int NR_ST=-1;
  255. int MAX_ST=0;
  256. #endif
  257.  
  258. #ifndef CONFIG_CHR_DEV_SG
  259. unsigned long sg_init(unsigned long memory_start, unsigned long memory_end){
  260.   return memory_start;
  261. };
  262. unsigned long sg_init1(unsigned long memory_start, unsigned long memory_end){
  263.   return memory_start;
  264. };
  265. void sg_attach(Scsi_Device * SDp){
  266. };
  267. int NR_SG=-1;
  268. int MAX_SG=0;
  269. #endif
  270.